import baseconfig from "./config.js"
import { useInfoStore } from '@/stores/info'

export default {
	post: function(url, data, success, options = {
		loading: true,
		title: '加载中...'
	}, fail) {
		data = data || {}
		if (options && options.loading) uni.showLoading({
			title: options.title
		})
		const infoStore = useInfoStore();
		uni.request({
			url: baseconfig.baseUrl + url,
			data,
			header: {
				sign: '5INXPL66OlOKRfsWB8G8',
				Authorization: infoStore.Authorization,
			},
			method: 'POST',
			success: res => {
				success(res.data)
			},
			fail,
			complete: () => {
				if (options.loading) uni.hideLoading()
			}
		})
		return url
	},
	timestampToTime(timestamp){
		  if (!timestamp) return;
		  let date  = new Date(Number(timestamp * 1000));
		  let Y = date.getFullYear();
		  let M = ( date.getMonth()+1<10 ? '0'+(date.getMonth()+1) : date.getMonth()+1 ) //要不要＋0看需求
		  let D = date.getDate()<10?'0'+date.getDate():date.getDate();//不需要加0这样处理就可以,需要就按照M逻辑来处理
		  let hh = date.getHours()<10?'0'+date.getHours():date.getHours();
		  let mm = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
		  let ss = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
		  return Y + '-' + M + '-' + D + ' ' + hh + ':' + mm + ':' + ss
	},
	// secondTohours(seconds){
	// 	  var secondTime = parseInt(seconds);// 秒
	// 	  var minuteTime = '00';// 分
	// 	  var hourTime = '00';// 小时
	// 	  if(secondTime > 59) {//如果秒数大于60，将秒数转换成整数
	// 	    minuteTime = addzero(parseInt(secondTime / 60))
	// 	    secondTime = addzero(parseInt(secondTime % 60))
	// 	    if(minuteTime > 59) {
	// 	      //获取小时，获取分钟除以60，得到整数小时
	// 	      hourTime = addzero(parseInt(minuteTime / 60))
	// 	      //获取小时后取佘的分，获取分钟除以60取佘的分
	// 	      minuteTime = addzero(parseInt(minuteTime % 60))
	// 	    }
	// 	  }else{
	// 	    secondTime=addzero(secondTime)
	// 	  }
		
	// 	  return hourTime+ ":" + minuteTime + ":" +secondTime
	// }
}